package edu.ustb.services.weatherforecast.contract;

import edu.ustb.sc.definitions.*;
/*
term no3_2: Provider must offer(service)
         when reponses.code == 200
         while withdraw price
         where this.balance >= 0.
 */
public class ServiceTerm3_2  extends SpescContractTerm <ServiceContract> {

    public ServiceContractParty partyInfo = new ServiceContractParty("Provider");

    public static SpescTermActionQualifierEnum qualifier = SpescTermActionQualifierEnum.Can;

    public static String actionName = "offer";

    public ServiceTerm3_2() {
        try {
            actionInfo = new ContractActionInfo();
            actionInfo.setAction(ServiceContract.class.getMethod("offer"));
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        }
    }

    @Override
    public TermLogicEnum getLogic() {
        return null;
    }

    @Override
    public String getTermName() {
        return "ServiceTerm3_2";
    }

    @Override
    public SpescTermActionQualifierEnum getQualifier() {
        return qualifier;
    }

    @Override
    public ContractPartyInfo getPartyInfo() {
        return partyInfo;
    }

    @Override
    public SpescConditionCheckStatus whenPreCondition(ServiceContract contract, Object... param) {
        try {
            ContractActionInfo requestAction = new ContractActionInfo(ServiceContract.class
                    .getDeclaredMethod("request",String.class,String.class),
                    new Object[2]);
            if (contract.isActionDid(requestAction)) {
                return SpescConditionCheckStatus.Yes;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return SpescConditionCheckStatus.No;

    }

    @Override
    public SpescConditionCheckStatus wherePostCondition(ServiceContract contract, Object... param) {
        return SpescConditionCheckStatus.Yes;

    }
}
